package com.problem;

import java.util.HashMap;
import java.util.Map;

public class sa01 {

    public static void main(String[] args) {
        int[]  s = {2,7,4,5};
        int[] a1  =  twoSum(s,9);
        System.out.println(a1[0]+" "+ a1[1] );
    }
    //2 7  4 5
    //
    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> m = new HashMap<Integer, Integer>();
        int[] res = new int[2];
        for (int i = 0; i < nums.length; ++i) {
            if (m.containsKey(target - nums[i])) {
                res[0] = i;
                res[1] = m.get(target - nums[i]);
                break;
            }
            m.put(nums[i], i); //2 0
        }
        return res;
    }
}
